var encoding = require('encoding')
var xdb = require('xdb')

function main() {
  xdb.new('zcx', `/database/zcx`)
  const document = JSON.parse(encoding.from(payload.body))
  let result = true
  try {
    Object.keys(document).forEach((item) => {
      xdb.setDocumentByID(
        'zcx',
        'department',
        document.id,
        item,
        document[item]
      )
    })
  } catch (e) {
    result = false
  }

  return result
}
